var app = getApp();
const cnConvert = require('../../utils/changefont.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cruIdx:1,
    id:0,
    dataList:[],
    notice:[],
    makerComboMsgList:[],
    item:{},
    pageText:{
      'jqbh':'机器编号',
      'jqmc':'机器名称',
      'jqwz':'机器位置',
      'yhtc':'优惠套餐',
      'yj':'原价'
    }
  },

  onLoad: function (options) {

    this.setData({
        item: JSON.parse(options.item)
    })
    if (wx.getStorageSync('userDo').font == 1) { //切换繁体
      var textObj = this.data.pageText
      for (var item in textObj) {
        textObj[item] = cnConvert.traditionalized(textObj[item])
      }
      this.setData({
        pageText: textObj
      })
     
    }
    wx.setNavigationBarTitle({ title: this.data.item.name })
    this.getDataList();
  
  },
  tapMenu:function(e){
        this.setData({
            cruIdx: e.currentTarget.dataset.idx
        })

        if (this.data.cruIdx == 3){
            this.getMakerComboMsg();
        }
  },

  getMakerComboMsg:function(){
      var that = this;
      wx.request({
        url: app.globalData.api + 'getMakerComboMsg/' + that.data.item.id + '/' + wx.getStorageSync('userDo').font,
          success: function (res) {
              if (res.statusCode) {
                  that.setData({
                      makerComboMsgList: res.data
                  })
              }
          }
      })
  },
  getDataList:function(){
    var that = this;
    wx.request({
      url: app.globalData.api + 'getSaleByMakerId?makerId=' + that.data.item.id + '&font=' + wx.getStorageSync('userDo').font,
        success:function(res){
            if (res.statusCode){
                that.setData({
                    dataList:res.data
                })
            }
        }
    })
  }

})